data1<-read.table("E:/R Studio/shixi/shixi 3/ADdata/ADdata1.txt",header=TRUE)#读取txt文件
matrixdata<-as.matrix(data1)#转化成矩阵
hist(matrixdata)#绘图
distance<-dist(data1)#测距离
tree<-hclust(distance,method="average")#使用平均链接法进行聚类
plot(tree)#显现出树图
install.packages("ggplot2") 
library(ggplot2)
install.packages("ggrepel")
library(ggrepel)
load("E:/R Studio/shixi/shixi 4/volcano.RData")
p<-ggplot(data=prostat,aes(x=FC,y=-log10(P)))+ #读取数据设xy轴
  geom_point(color="yellow")+ #散点颜色设为黄色
  geom_hline(yintercept=-log10(0.05),linetype=4,color="red")+ #在y轴上加截距为-log10（0.05）也就是p=0.05的红色水平虚线
  geom_vline(xintercept=c(-log2(1.2),log(1.2)),linetype=4,color="blue") #在x轴上加fc值为1.2和-1.2的蓝色竖直虚线
p<-p+
p<- p +
  geom_text_repel(aes(label=ID),color="black",size=3)#带上文本标签
ggsave("volcanoplot.jpg")#保存volcano.jpg
print(p)#输出p

up<-prostat[prostat$P<0.05&prostat$FC>1.2,]
down<-prostat[prostat$P<0.05&prostat$FC<(1/1.2),]
prostat$significance<-ifelse(prostat$P<0.05&prostat$FC>1.2,"up",ifelse(prostat$P<0.05&prostat$FC<(1/1.2),"down","Not_Significant"))
library(ggplot2)
library(ggrepel)
volcano_plot<-ggplot(prostat,aes(x=FC,y=-log10(P),color=significance))+
  geom_point(alpha=0.6,size=2)+
  scale_color_manual(values=c("up"="red","down"="blue","Not_Significant"="grey"))+
  labs(x="FC",y="-log10(P)",color="significance")+
  geom_text_repel(aes(label=ID),color="black",size=2)
volcano_plot
ggsave("E:/R Studio/shixi/shixi 4/volcano_plot")


